package com.example.demo.filters.inbound;

import com.netflix.zuul.context.SessionContext;
import com.netflix.zuul.filters.http.HttpInboundSyncFilter;
import com.netflix.zuul.message.http.HttpRequestMessage;

/**
 * @author sleepforests
 * Created on 2019-06-27
 */
public class MetricsInboundFilter extends HttpInboundSyncFilter {
    public static final String METRICS_FILTER_KEY = "_METRICS_FILTER_KEY";

    @Override
    public HttpRequestMessage apply(HttpRequestMessage request) {
        SessionContext ctx = request.getContext();
        long begin = System.currentTimeMillis();

        ctx.put(METRICS_FILTER_KEY, begin);


        return request;
    }

    @Override
    public int filterOrder() {
        return -2;
    }

    @Override
    public boolean shouldFilter(HttpRequestMessage msg) {
        return true;
    }
}
